package cc.eddic.practice.concurrency;

import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ExecutorServiceUtil {
    public static void shutdown(ExecutorService executorService) {
        try {
            if (log.isDebugEnabled()) log.debug("shutdown executorService");
            executorService.shutdown();

            if (log.isDebugEnabled()) log.debug("awaitTermination executorService");
            val b = executorService.awaitTermination(10, TimeUnit.MINUTES);
            if (log.isDebugEnabled()) log.debug("awaitTermination executorService : {}", b);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        } finally {
            if (log.isDebugEnabled()) log.debug("shutdownNow executorService");
            executorService.shutdownNow();
        }

    }
}
